﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Management/Manage.Master"  %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Show Menu
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 <script type="text/javascript">
     $(document).ready(function () {

         $("a").removeClass("current");
         $("#categories").addClass("current");
         var e = jQuery.Event("click");
         $("#categories").trigger(e);
         $("#list-categories").addClass("current");

     });

     function Delete(id) {
         var answer = confirm("Do you want to delete this category?")
         if (answer) {
             DeleteCategory(id);
         }

         return false;
     }

     function DeleteCategory(id) {


         $("#results").html("");
         $.ajax({
             type: "POST",
             url: "/Management/DeleteCategory/" + id,
             error: function (xhr, status, error) {
             },
             success: function (response) {
                 if (response != null) {
                     if (!response.Successful) {
                         $("#results").html("An error occurred: " + response.Exception).addClass("red");
                         return false;
                     }
                     else {
                        // window.opener.location.reload();
                         window.location.reload();
                         $("#results").html("Category Deleted Successfully.").addClass("green");
                     }
                 }
             }
         });

     }
        
</script>
<div class="content-box">
        <!-- Start Content Box -->
        <div class="content-box-header" style="padding:4px 0px 0px 10px;">
            <h3>Categories</h3>
            <div class="clear">
            </div>
        </div>
          <div class="content-box-content">
          <div id="results"></div>
          <div class="tab-content default-tab" id="tab1">
            <table>
                    <thead>
                    <tr>
                    <th>Title</th>
                    <th>Create Date</th>
                    <th colspan="2" >Actions</th>
                    </tr>
                    </thead>
                    <tbody>
                    <% foreach (var c in ((IList<CSI.Directory.Core.Model.Category>)ViewData["Categories"]).Where(t=>t.ParentId == 0).ToList())
                    {%>
                    <tr>
                    <td>
                        <%if(((IList<CSI.Directory.Core.Model.Category>)ViewData["Categories"]).Where(t=>t.ParentId == c.Id).ToList().Count > 0){ %>
                            <a href="#" onclick="$(this).next('.<%=c.Id%>').css('display','block'); return false;"><b><%=c.Name %></b></a>
                        <%}else{ %>    
                            <%=c.Name %>
                        
                        <%} %>
                        <div class="<%=c.Id %>" style="display:none">
                        <br />
                    <% foreach (var s in ((IList<CSI.Directory.Core.Model.Category>)ViewData["Categories"]).Where(t => t.ParentId == c.Id).ToList())
                    {%>
                            
                         <a href="" onclick="Delete(<%= c.Id%>);return false;">Delete</a>&nbsp;&nbsp;&nbsp;&nbsp;
                         <%=s.Name %>      
                        
                           
                        
                        <br /><br />
                        
                        
                    <%} %> 
                    </div>
                    </td>
                        
                    <td><%=c.CreateDate%></td>
                  
                     <td><a href="" onclick="Delete(<%= c.Id%>);return false;">Delete</a></td>
                    
                    </tr>
                    
                    
                    <%} %>
                    </tbody>
            </table>
           </div>
        </div>
  </div>
    
</asp:Content>
